/* 
 * @Author: zhuzhu
 * @Date:   2016-10-10 14:32:41
 * @Last Modified by:   bingo
 * @Last Modified time: 2016-10-14 10:26:53
 */

(function (app) {
	var app = angular.module('myApp', ['azcl.common.directive']);
    app.controller("HealthQuestionnaireCtrl", function ($scope, $http,$timeout) {

    	//数据初始化
    	$scope.options1 = [{ val: "0" }, { val: "1" }, { val: "2" }, { val: "3" }, { val: "超过3" }];
        $scope.options2 = [{ val: "1" }, { val: "2" }, { val: "3" }, { val: "超过3" }];
        $scope.options3 = [{ val: "140以下" }, { val: "141-150" }, { val: "151-160" }, { val: "160以上" }, { val: "不清楚" }];
        $scope.options4 = [{ val: "90以下" }, { val: "91-95" }, { val: "96-100" }, { val: "101-105" }, { val: "106-110" }, { val: "110以上" }, { val: "不清楚" }];
        $scope.options5 = [{ val: "白酒" }, { val: "威士忌" }, { val: "白兰地" }, { val: "烈酒" }, { val: "黄酒" }, { val: "葡萄酒/红酒" }, { val: "啤酒" }];
        $scope.options6 = [{ val: "复查完全正常" }, { val: "复查仍有异常" }, { val: "未复查" }];
        $scope.options7 = [{ val: "复查正常" }, { val: "复查仍有异常" }, { val: "未复查" }];
        $scope.options39 = [{ val: "复查正常" }, { val: "复查异常" }, { val: "未复查" }];
        $scope.options8 = [{ val: "急性" }, { val: "慢性" }];
        $scope.options9 = [{ val: "甲型" }, { val: "乙型" }, { val: "丙型" }, { val: "丁型" }, { val: "戊型" }, { val: "两种或两种以上不同类型" }, { val: "不明类型" }];
        $scope.options10 = [{ val: "良性" }, { val: "恶性" }, { val: "性质不清楚" }];
        $scope.options11 = [{ val: "两" }, { val: "毫升" }];
        $scope.options12 = [{ val: "尚未痊愈" }, { val: "痊愈未满6个月" }, { val: "痊愈已满6个月" }, { val: "痊愈已满1年" }];
        $scope.options13 = [{ val: "尚未痊愈" }, { val: "痊愈未满6个月" }, { val: "痊愈已满6个月" }, { val: "痊愈已满1年" }, { val: "痊愈已满2年" }, { val: "痊愈已满3年" }];
        $scope.options14 = [{ val: "完全正常" }, { val: "曾有异常" }, { val: "未检查" }];
        $scope.options15 = [{ val: "未做过" }, { val: "正在进行中" }, { val: "结束未满6个月" }, { val: "结束已满6个月" }, { val: "结束已满1年" }, { val: "结束已满2年" }, { val: "结束已满3年" }];
        $scope.options16 = [{ val: "未做过" }, { val: "正在进行中" }, { val: "结束未满6个月" }, { val: "结束已满6个月" }, { val: "结束已满1年" }, { val: "结束已满2年" }, { val: "结束已满3年" }, { val: "结束已满4年" }, { val: "结束已满5年" }];
        $scope.options17 = [{ val: "无" }, { val: "1次" }, { val: "2次" }, { val: "3次" }, { val: "超过3次" }];
        $scope.options18 = [{ val: "小于0.1" }, { val: "0.1-0.2" }, { val: "0.2-0.3" }, { val: "0.3-0.4" }, { val: "0.4-0.5" }, { val: "0.5-0.6" }, { val: "0.6-0.7" }, { val: "0.7-0.8" }, { val: "0.8-0.9" }, { val: "0.9-1.0" }, { val: "超过1.0" }];
        $scope.options20 = [{ val: "小于1" }, { val: "1-2" }, { val: "2-3" }, { val: "3-4" }, { val: "4-5" }, { val: "超过5" }];
        $scope.options21 = [{ val: "小于6个月" }, { val: "6个月至1年" }, { val: "1-2年" }, { val: "2-3年" }, { val: "3-4年" }, { val: "4-5年" }, { val: "超过5年" }];
        $scope.options22 = [{ val: "小于6个月" }, { val: "6个月至1年" }, { val: "1-2年" }, { val: "2-3年" }, { val: "超过3年" }];
        $scope.options38 = [{ val: "小于6个月" }, { val: "6个月至1年" }, { val: "1-2年" }, { val: "超过2年" }];
        $scope.options23 = [{ val: "已" }, { val: "未" }];
        $scope.options24 = [{ val: "已经" }, { val: "尚未" }];
        $scope.options25 = [{ val: "已手术切除子宫" }, { val: "已手术切除全部肌瘤但保留子宫" }, { val: "未手术" }];
        $scope.options26 = [{ val: "已做" }, { val: "未做" }];
        $scope.options27 = [{ val: "有" }, { val: "无" }];
        $scope.options28 = [{ val: "曾" }, { val: "未曾" }];
        $scope.options29 = [{ val: "曾有" }, { val: "未曾有" }];
        $scope.options30 = [{ val: "曾有" }, { val: "无" }];
        $scope.options31 = [{ val: "正常" }, { val: "仍有结石" }, { val: "未检查" }];
        $scope.options32 = [{ val: "正常" }, { val: "异常" }, { val: "未检查" }];
        $scope.options33 = [{ val: "左侧" }, { val: "右侧" }, { val: "双侧" }];
        $scope.options34 = [{ val: "左肾" }, { val: "右肾" }, { val: "双肾均有" }];
        $scope.options35 = [{ val: "左输尿管" }, { val: "右输尿管" }, { val: "双输尿管均有" }];
        $scope.options36 = [{ val: "左眼" }, { val: "右眼" }, { val: "双眼" }];
        $scope.options37 = [{ val: "左眼已做" }, { val: "右眼已做" }, { val: "双眼已做" }, { val: "双眼均未做" }];
        
        //返回上一步
        $("#goBack").click(function(){
    		window.location.href="/pad_marketing/main/gotoOther.action";
    	});
        
        
    	$timeout(function(){//延迟加载数据
    		var params = JSON.parse(sessionStorage.appBase); 
    		console.log(params)
			//初始化页面调取数据
    		padMarketing.ajaxNormal('/pad_marketing/main/editHQ.action',params,
				function(data){
					$scope.app = data;
					//类型转换
				    angular.forEach($scope.app.cps ,function(cp){
				    	if(cp.hqV5){
					    	cp.hqV5.q1000A = cp.hqV5.q1000A == null ? null : Number(cp.hqV5.q1000A);
					    	cp.hqV5.q1000B = cp.hqV5.q1000B == null ? null : Number(cp.hqV5.q1000B);
					    	cp.hqV5.q3400A = cp.hqV5.q3400A == null ? null : Number(cp.hqV5.q3400A);
				    	}
				    });
				    

		            console.log($scope.app.cps);
				    
		            for (var i in $scope.app.cps)//循环数据
		            {
		                if ($scope.app.cps[i].isInsured)
		                {	
		                	//数据模型被改变,页面不刷新的解决办法$scope.$apply
		                	$scope.$apply(function(){
			                    $scope.cp = $scope.app.cps[i];
		                	});
		                    break;
		                }
		            }
				},
				function(data){
					 $scope.app = null;
				}
			);
		},200);
    	
    	//投被保人点击事件
        $scope.setCp=function(cp){
        	if ($scope.cp === cp) return;
            if ($scope.myForm.$invalid)
            {
                alertMsg("请先完成当前健康告知。");
                return;
            }
        	$scope.cp = cp;
        };
        
      //答题小项单选
    	$scope.gzTogglebtn = function(e){
    		$(e.target).toggleClass("check_yes","check_no");
    	};
    	 
    	//答题小项单选2 有/无肾盂肾炎
    	$scope.gzTogglebtn2 = function(e){
    		$(e.target).removeClass("check_no").addClass("check_yes");
    		$(e.target).siblings("label").addClass("check_no").removeClass("check_yes");
    	};
    	
    	
    	//全部否按钮
    	$scope.judgeAllno = function(){
    		alertMsg("请确认您已如实填写健康告知内容!",1,function(){
    			$scope.$apply(function(){
    				$scope.cp.hqV5.q1200 ='N';
            		$scope.cp.hqV5.q1300 ='N';
            		$scope.cp.hqV5.q1400 ='N';
            		$scope.cp.hqV5.q1500 ='N';
            		$scope.cp.hqV5.q1600 ='N';
            		$scope.cp.hqV5.q1700 ='N';
            		$scope.cp.hqV5.q1800 ='N';
            		$scope.cp.hqV5.q1900 ='N';
            		$scope.cp.hqV5.q2000 ='N';
            		$scope.cp.hqV5.q2100 ='N';
            		$scope.cp.hqV5.q2200 ='N';
            		$scope.cp.hqV5.q2400 ='N';
            		$scope.cp.hqV5.q2500 ='N';
            		$scope.cp.hqV5.q2600 ='N';
            		$scope.cp.hqV5.q2700 ='N';
            		$scope.cp.hqV5.q2800 ='N';
            		$scope.cp.hqV5.q3000 ='N';
            		$scope.cp.hqV5.q3100 ='N';
            		$scope.cp.hqV5.q3200 ='N';
            		$scope.cp.hqV5.q3500 ='N';
            		$scope.cp.hqV5.q3600 ='N';
            		$scope.cp.hqV5.q3700 ='N';
            		$scope.cp.hqV5.q3800 ='N';
            		$scope.cp.hqV5.q4000 ='N';
            		$scope.cp.hqV5.q4100 ='N';
            	}); 
    			
    		});
    		
    	};
    	
    	//alert homebtn
    	//重新改写弹出框
    	$scope.alertHomebtn=function(){
    		$("body").css("overflow","hidden");
    		$("#gz-aleratAll").css("height",$(window).height()); 
    		$("#gz-aleratAll").css("top",document.body.scrollTop); 
    		$("#gz-aleratAll").removeClass("hide");
    		$(".circle-panel").removeClass("hide");
    	};
    	$scope.alertHomebtnClose=function(){
    		$("body").css("overflow","visible");
    		$("#gz-aleratAll").addClass("hide");
    		$(".circle-panel").addClass("hide");
    	};
    	
    	
    	
    	//下一步提交数据
    	$scope.gzNext = function () {
    		
     		var param = $scope.app;
     		
     		padMarketing.ajaxNormal('/pad_marketing/main/saveHQ.action',param,
 				function(data){
	     			// 是否有需要CRS的人
	                var needCRS = false;
	                for (var i = 0; i < $scope.app.cps.length; i++) {
	                    if ($scope.app.cps[i].needCRS == "true") {
	                        needCRS = true;
	                        break;
	                    }
	                }
     				
     				if(needCRS == true){
     					//如果CP需要crs跳转到crs问卷页面
     					window.location = "/pad_marketing/crsAction/toCRS.action";
     				}
     				else if($scope.app.appBase.productGroup3 == "UNIT LINK"){
     					//如果保单为投连险时 需跳转到风险评估页面
     	    			window.location = "/pad_marketing/main/gotoRiskAssess.action";
     				}
     				else{
     					sessionStorage.setItem('promptUrl','gotoHealthContent.action')
     					//如果保单不为投连险时直接跳转到投保提示书页面
     					window.location = "/pad_marketing/main/gotoCoverPrompt.action";
     				}

     				
     				
     				
 				},
 				function(data){
 					//错误提示
 				}
 			);
    		
        }
        
    });
}());